<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>七海后台管理系统</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <!-- 引入公共页面 -->
        {{include "./common/header.html"}}
        <!-- 引入公共页面 -->
        {{include "./common/side-menu.html"}}

        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding :15px">
                <span class="layui-breadcrumb" lay-separator=">">
                    <a href="/">首页</a>
                    <a href="/add">添加内容</a>
                </span>
                <form style="padding:15px;" class="layui-form" id="theform" lay-filter="formCate">
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容 </label>
                        <div class="layui-input-inline">
                            <input type="text" lay-verify="required" class="layui-input" name="cate_name"
                                autocomplete="off">
                        </div>
                    </div>
                    <div>
                        <label class="layui-form-label">显示首页：</label>
                        <input type="radio" name="is_show" value="1" title="显示">
                        <input type="radio" name="is_show" value="0" title="不显示">
                    </div>
                    <div class="layui-form-item">
                        <label>内容:</label>
                        <div id="demo">

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">添加</button>
                        </div>
                    </div>
            </div>
            </form>
        </div>
    </div>
    <!-- 引入公共页面 -->
    {{include "./common/footer.html"}}
</body>
<script src="/static/js/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
<!-- <script src="/static/js/edit.js"></script> -->
<script>
    layui.use(['element', 'layer', 'util', 'form'], function () {
        var element = layui.element
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$;
        // head
        util.event('lay-header-event', {
            //左侧菜单
            menuleft: function (othis) {
                layer.msg('展开左侧菜单的操作', { icon: 0 });
            }
            , menuRight: function () {
                layer.open({
                    type: 1
                    , content: "<div style='padding:15px';>处理右侧面板的操作</div>"
                    , area: ['260px', "100%"]
                    , offset: 'rt' //右上角
                    , anim: 5
                    , shadeClose: true
                });
            }
        })
    })

    //   初始化富文本编辑器
    const E = window.wangEdite
    const editor = new E('#demo')
    editor.config.uploadImgShowBase64 = true
    // 或 const editor = new E(document.getElementById('div1'))
    editor.create();
    // 获取url地址中的cat_id
    // let url = location.href;
    // let queryString = url.slice(url.indexOf('?')+1)
    // let cat_id = queryString.split('=')[1];


    let reg = /cat_id=(\d+)\&?/;
    let url = location.href;
    let [, cat_id] = [...url.match(reg)]
    console.log(cat_id);
    
    $('#setContent').click(function(event){
      event.preventDefault();//阻止默认行为
      let content = editor.txt.html();
      $.post('/updateArtilceContent',{content,id},res=>{
          let {code,message} = res;
          layui.msg(msgssage)
          if(code=20000){
              location.href="/article";
          }
      },'json')
    })
   
</script>

</html>